package com.ewili.framework.exception;


import com.ewili.framework.utils.GlobalConstant;

/**
 * 业务异常类。
 * 实现了ResponseStatusCoded，所以也可以用于生成Response。
 *
 * @author leo
 */
public class BusinessException extends RuntimeException implements ResponseStatusCoded {

    private static final long serialVersionUID = 1L;

    private final int responseStatus;

    /**
     * 使用 ResponseStatus.ERROR构建一个 BusinessException
     */
    public BusinessException() {
        responseStatus = GlobalConstant.ResponseStatus.ERROR;
    }

    /**
     * 使用 ResponseStatus构建一个 BusinessException
     */
    public BusinessException(int status) {
        responseStatus = status;
    }

    /**
     * 使用 ResponseStatus.ERROR和 message构建一个 BusinessException
     *
     * @param message
     */
    public BusinessException(String message) {
        super(message);
        responseStatus = GlobalConstant.ResponseStatus.ERROR;
    }

    /**
     * 使用 ResponseStatus和 message构建一个 BusinessException
     *
     * @param status
     * @param message
     */
    public BusinessException(int status, String message) {
        super(message);
        responseStatus = status;
    }

    /**
     * 获取描述此异常的Response
     *
     * @return
     */
    @Override
    public int getResponseStatus() {
        return responseStatus;
    }
}